package cn.itcast.saveqq;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btn_Login;
    private EditText et_Account;
    private EditText et_Password;
    private void initView(){
        btn_Login = (Button)findViewById(R.id.btn_login);
        et_Account = (EditText)findViewById(R.id.et_account);
        et_Password = (EditText)findViewById(R.id.et_password);
        btn_Login.setOnClickListener(this);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        //Map<String, String> userInfo = FileSaveQQ.getUserInfo(this);
        /*Map<String,String> userInfo = SPSaveQQ.getUserInfo(this);
        if(userInfo != null){
            et_Account.setText(userInfo.get("account"));
            et_Password.setText(userInfo.get("password"));
        }*/
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_login:
                String account = et_Account.getText().toString().trim();
                String password = et_Password.getText().toString();
                if(TextUtils.isEmpty(account)){
                    Toast.makeText(this,"请输入账号", Toast.LENGTH_SHORT).show();
                    return;
                }
                if(TextUtils.isEmpty(password)){
                    Toast.makeText(this,"请输入密码",Toast.LENGTH_SHORT).show();
                    return;
                }
                //Toast.makeText(this,"登录成功",Toast.LENGTH_SHORT).show();
                //boolean isSaveSuccess = FileSaveQQ.saveUserInfo(this, account, password);
                //ActivityCompat.requestPermissions(this,new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"},1);
                //boolean isSaveSuccess = FileSaveQQ.saveUserInfoExt(this, account, password);
                //boolean isSaveSuccess = SPSaveQQ.saveUserInfo(this, account, password);
                //SQLiteSaveQQ.insert(this,"12345","ASB");
                //boolean isSaveSuccess = true;
                boolean isSaveSuccess = SQLiteSaveQQ.validUserInfo(this,account,password);
                if(isSaveSuccess){
                    Toast.makeText(this,"该用户信息已存在",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(this,"该用户信息不存在",Toast.LENGTH_SHORT).show();
                    SQLiteSaveQQ.insert(this,account,password);
                }
                break;
        }
    }
}